fix(eval): sort json2md GT when extra has no usable relation list - #4
Merged
Merged
Conversation
_merge_truncated_json2md skipped the final sort-by-order step when row['extra'] was present but row['extra']['relation'] was missing, None, or not a list. Real OmniDocBench manifest rows can carry an 'extra' dict that holds keys other than 'relation' (or sets 'relation' to a non-list value), so this branch is reachable. When triggered, prepare_annos_json2md returned blocks in manifest order rather than reading order, which means: - gt_markdown_json2md emitted GT markdown out of reading order. - _gt_markdown_for_eval (json2md strategy) fed misordered GT into NED/CER for those rows, biasing baseline-*.json results. - _compute_per_category_metrics zipped pred blocks against misordered GT annos, attributing wrong text/table/formula NED/TEDS scores to the wrong GT blocks. The reference tools/json2md.py from OmniDocBench always finishes with sorted(merged_annos, key=lambda x: x['order']) (see docs/eval/json2md-reference.md). Mirror that ordering in the no-relation branch by sorting before returning. Add a regression test covering three triggers: - extra dict with only unrelated keys - extra['relation'] explicitly None - extra['relation'] set to a dict instead of a list Co-authored-by: Bartłomiej Rosa <bartrosa@users.noreply.github.com>
bartrosa
marked this pull request as ready for review
May 23, 2026 12:45
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug and impact
bigos.eval.omnidocbench._merge_truncated_json2mdsilently skipped the final sort-by-orderstep when a manifest row hadextraset to a truthy dict butextra["relation"]was missing,None, or not a list. When triggered,prepare_annos_json2mdreturned blocks in manifest order rather than reading order, causing the json2md GT pipeline to emit misordered GT markdown.Concrete blast radius for OmniDocBench evaluation runs:
gt_markdown_json2mdwrites GT pieces in the wrong order for affected rows._gt_markdown_for_eval(json2md strategy, the default) feeds that misordered GT into character-level metrics —cer,ned,cer_normalized,ned_normalized,len_ratio— biasing per-sample and aggregate numbers persisted ineval/results/baseline-*.jsonand the markdown report._compute_per_category_metricswalksprepare_annos_json2md(row)and zips againstpredblocks in reading order; misordered annos cause wrong-cell attribution oftext_ned,table_teds, andformula_nedto the wrong category buckets.Trigger: any OmniDocBench manifest row whose
extradict carries keys other than a list-typedrelation. The referencetools/json2md.pyalways finishes withsorted(merged_annos, key=lambda x: x['order'])(documented indocs/eval/json2md-reference.md), so the previous behavior diverged from the documented contract whenever this branch was reached.Root cause
The
if not extrabranch and the post-merge return both sort byorder. The middle branch — taken whenextraexists but doesn't contain a usablerelationlist — was the only exit that returned the filtered annos in their original manifest order.Fix and validation
Sort by
orderin the no-relation branch as well, mirroring the referencetools/json2md.pyend-of-pipeline sort.Validation:
tests/test_eval_omnidocbench.py::test_extra_without_relation_still_sorts_by_ordercovering three concrete triggers:extrawith only unrelated keys,extra["relation"] is None, andextra["relation"]set to a dict. Confirmed the test fails on the previous code (assert 8 < 0from'second\n\nfirst') and passes on the fix.pytest -m "not slow") green: 54 passed.No broad refactor; the change is one branch and one regression test.